import { type } from "os"

export function successReturn(data:any = null, params?:{[key : string] : any}) {
    let result:{[key : string] : any} = {
        success : true,
        data : null,
        msg : '请求成功',
        code : 0
    }

    if(data !== null) {
        result.data = data
    }

    if(params) {
        result = Object.assign(result, params)
    }

    return result
    
}

export function errorReturn(msg?:string, params?:{[key : string] : any}) {
    let result:{[key : string] : any} = {
        success : false,
        data : null,
        msg : msg || '请求失败',
        code : 0
    }

    if(msg !== undefined) {
        result.msg = msg
    }

    if(params) {
        result = Object.assign(result, params)
    }

    return result
    
}


export function getTime() : number{
    return Math.floor((new Date()).getTime() / 1000)
}

export function isPlatform(type) {
    return type == 0
}

export function isMerchant(type) {
    return type == 1
}

export function isSubMerchant(type) {
    return type == 2
}